<template>
    <v-dialog
            v-model="dialogVisible" v-if="user"
            width="500"
    >
        <v-card>
            <v-card-title
                    class="headline grey lighten-2"
                    primary-title
            >
                举报
            </v-card-title>
            <v-card-text class="pt-10px">
                <v-radio-group v-if="reportType && reportType!==$const.reportType.noViolation" v-model="reportType">
                    <v-radio
                            v-for="item in $const.reportType.reportTypes"
                            :key="item.value"
                            :label="item.name"
                            :value="item.value"
                    ></v-radio>
                </v-radio-group>
                <v-textarea
                        v-model="content"
                        label="备注"
                        outlined
                        rows="7"
                        placeholder="非必填，如想详细描述观点可在这里补充"
                ></v-textarea>
            </v-card-text>
            <v-divider></v-divider>
            <v-card-actions class="row-around">
                <v-btn outlined color="secondary" class="w40r" @click="closeDialog">
                    取消
                </v-btn>
                <v-btn :disabled="!reportType" depressed color="info" class="w40r" @click="addReport">
                    确定
                </v-btn>
            </v-card-actions>
        </v-card>
    </v-dialog>
</template>

<script lang="ts">
  import {Vue, Component, Prop, Watch} from 'vue-property-decorator'
  import ReportAdd from "@/model/ReportAdd"
  import InfoType from "@/const/InfoType"
  import User from "@/model/User"

  /**
   * 举报一条信息，只有同意和支持，然后几率，
   */
  @Component
  export default class ReportDialogVue extends Vue {
    dialogVisible: boolean = false
    reportType: string = ''
    content: string = ''
    user: User = null

    initData() {
      this.content = ''
      this.reportType = ''
      this.dialogVisible = false
    }

    open(user: User, reportType?: string) {
      this.user = user
      this.reportType = reportType || ''
      this.dialogVisible = true
    }

    closeDialog() {
      this.initData()
    }

    addReport() {
      this.$info("举报正确会奖励2个清池币，举报错误会惩罚扣除1个清池币，请确认是否举报！").then(({result}) => {
        if (result) {
          const reportAdd: ReportAdd = new ReportAdd()
          reportAdd.receiveUserId = this.user.id
          reportAdd.infoType = InfoType.user
          reportAdd.type = this.reportType
          reportAdd.content = this.content
          reportAdd.infoVersionNo = 1
          this.$post('report/addReport', reportAdd)
        }
      })
    }
  }
</script>
